package leetcode;

/**
 * @author : zx
 * @version V1.0
 */
public class RotatingImage {

    /*
     * 题目：方阵右旋
     * 思路：先转置，再做左右对称列交换
     */
    private static void rotate(int[][] matrix) {
        int width = matrix[0].length;
        int height = matrix.length;
        int tmp ;
        for (int i = 0; i < height; i++){
            for (int j = 0; j <= i; j++){
//                System.out.printf("(%d, %d)", i, j);
                tmp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = tmp;
            }
        }

        for (int i = 0; i < height; i++){
            for (int j = 0; j < width/2; j++){
                tmp = matrix[i][j];
                matrix[i][j] = matrix[i][width - 1 - j];
                matrix[i][width - 1 - j] = tmp;
            }
        }
    }

    /*
     * 方法2 找到旋转的四个坐标点， (i,j), (n-1-i,n-1-j), (i,n-1-j), (n-1-i,j)
     */

    public static void main(String[] args){
        int[][] a = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
        rotate(a);
    }
}
